<%@page import = "clothing.database.EmployeeManager" %>

<%@page import = "clothing.database.MValidation" %>


<%@ include file = "templates/header.jsp" %>


<%
	if(request.getParameter("errorID")!=null)
{
	String errorID = request.getParameter("errorID");
	if(errorID.equals("1"))
	{
		out.println("<div> Please login </div>");
	}
}



if(request.getParameter("username")!=null)
{
	System.out.println("manager page1");
	String username = request.getParameter("username");
	String password = request.getParameter("password");
	
	
	
	EmployeeManager uh = new EmployeeManager();
	int count = uh.authenticate(username, password);
	
	if(count>=1)
	{
		System.out.println("redirecting to manager page");
		session.setAttribute("username", username);
		session.setAttribute("loggedin", true);
		MValidation mn = new MValidation();
		session.setAttribute ("isManager",mn.getManager(username));
		
		if((Boolean)session.getAttribute("isManager"))
			response.sendRedirect("managerPage.jsp");
		else
			response.sendRedirect("membersarea.jsp");
		
	}
	

	else
	{
		out.println("<div> Error: invalid username and password combination </div><br />");
		session.setAttribute("loggedin", false);
	}
}
	
%>

<form action.jsp" method ="post" >

	<table>
		<tr></br>
			<td>Username </td> <td> <input type="text" name = "username" </td>
		</tr>
		<tr>
			<td>Password </td> <td> <input type="password" name = "password" </td>
		</tr>

		<tr>
		
			<td> </td> <td> <input type="submit" name = "submit" value = "login" > </td>
		</tr>

	</table>
</form>   
<%@ include file = "templates/footer.jsp" %>
